﻿<?php 

function DoCommandUpload($command_type)
{
	switch ($command_type)
	{
		case "upload_dress_packet":
			HttpAction_UpdateGoodsDressPacket();//套装上传
			break;
		default:
			HttpAction_UpdateGoods();			//商品上传、修改
			break;
	}
}

function DoCommandInfo($command_type)
{
	switch ($command_type) {
		case "query_type_1":
			HttpAction_GetGoodsType1(); //查询类别1
			break;
		case "query_type_2":
			HttpAction_GetGoodsType2();	//查询类别2
			break;	
		case "query_type_3":
			HttpAction_GetGoodsType3();	//查询类别3
			break;	
			
		case "select_goods_info": 
			HttpAction_GetGoodsInfo();	//查询某条商品信息
			break;
		case "delete_goods":
			HttpAction_DeleteGoods();	//删除某商品
			break;
		case "set_goods_is_new":
			HttpAction_SetGoodsIsNew();  //设置某商品新旧标记
			break;
		case "set_goods_is_sell":
			HttpAction_SetGoodsIsSell(); //设置某商品可售标记
			break;
			
		case "select_goods_dress_info": 
			HttpAction_getGoodsDressInfo();		//查询某套装信息
			break;
		case "delete_goods_dress":		 		//删除套装
			HttpAction_DeleteGoodsDress();
			break;
		case "set_goods_dress_is_new":
			HttpAction_SetGoodsDressIsNew(); 	//设置某套装新旧标记
			break;
		case "set_goods_dress_is_sell":
			HttpAction_SetGoodsDressIsSell(); 	//设置某套装可售标记
			break;	
		case "edit_all_dress_order_index":
			HttpAction_EditAllDressPacketOrderIndex(); //修改所有套装排序字段
			break;

		case "edit_auto_goods_info":
			HttpAction_edit_auto_goods_info(); 		//更加等级修改金币等
			break;
		case "edit_auto_goods_dress_info":
			HttpAction_edit_auto_goods_dress_info(); //套装更加等级修改金币等
			break;
		case "edit_auto_goods_dress_info_ext":
			HttpAction_edit_auto_goods_dress_info_ext(); //(限量版)套装更加等级修改金币等
			break;
		
		
		default:
			break;
	}
}

function DoCommandPagind($command_type)
{
	switch ($command_type) {
		/*
		case "select_total_count": // 通用分页查询
			HttpAction_GetTotalCount();
			break;
		case "query_paging": // 通用分页查询
			HttpAction_QueryPaging();
			break;
		*/
			
		case "get_goods_total": 		
			HttpAction_GetGoodsTotal();	//商品总数
			break;
		case "get_goods_list": 			
			HttpAction_GetGoodsList();	//获取商品列表
			break;

		case "get_goods_dress_total": 	//套装总数
			HttpAction_GetDressPacketTotal();
			break;
		case "get_goods_dress_list":	//套装列表
			HttpAction_GetDressPacketList();
			break;			
		default:
			break;
	}
}


// --------------------------分页---------------------------------
// 查询总行数
function HttpAction_GetTotalCount()
{
	$table_name = GetRequest("table_name");

	$str_sql = sprintf("select count(*) as total_count from %s",
	    EscapeString($table_name));

	DBHelper::QueryReturnJSON($str_sql);
}
// 查询分页数据
function HttpAction_QueryPaging()
{
	$table_name = GetRequest("table_name"); //表名
	$page_index = GetRequest("page_index"); //当前查询的页码
	$per_page_count = GetRequest("per_page_count"); //每页行数
	$select_parms = GetRequest("select_parms"); //
	$count = ($page_index - 1) * $per_page_count;

	$str_sql = sprintf("select %s from %s  limit %s,%s",
	    EscapeString($select_parms),
	    EscapeString($table_name),
	    $count,
	    EscapeString($per_page_count)
	    );

	DBHelper::QueryReturnJSON($str_sql);
}
 
//传头像
function HttpAction_UploadUserHeadPhoto()
{
	try
	{		
	//---
	//$fptest=fopen("./upload_log",'w');  
	//---
	
		$session_id = $_REQUEST["session_id"];
		$user_name = "";
		
		$b_user_name = false;		
		
		if(isset($_REQUEST["user_name"]))
		{
			$user_name = $_REQUEST["user_name"];
			
			if(strlen($user_name) > 0)
				$b_user_name = true;
		}
		$str_sql = "";
		
		if($b_user_name == true)
		{
			$str_sql = sprintf("select c_id from t_userinfo where c_basic_username='%s'",
				EscapeString($user_name));
		}
		else
		{
			$str_sql = sprintf("select c_id from t_userinfo where c_session_id='%s'",
				EscapeString($session_id));
		}


//---
/*
fwrite($fptest, $session_id . "\n");
fwrite($fptest, $user_name . "\n");
fwrite($fptest, $str_sql . "\n");
*/
//---

		$rArray = DBHelper::Query($str_sql, $msg);
		if($rArray == -1 || count($rArray) == 0)
			throw new Exception("fatal: session_id not exists. ". $msg);

		$userid = $rArray[0]["c_id"];  //根据session_id获取用户id

		$img = file_get_contents("php://input");
		if (!$img)
			throw new Exception("not image data");

		//$newPath = GetUploadPath() . GetConfInfo("update_path_photo") . $userid . "/";
		//$newName = $userid . ".png";     //文件名字
		$user_zone = intval($userid / 10000);
		$newPath = GetUploadPath() . GetConfInfo("update_path_photo") . $user_zone. "/" . $userid . "/";
		$newName =  $userid . ".png";
		$file_dir = $newPath . $newName; //全路径

		CreateFolder($newPath); //建立文件夹
		$fp = fopen($file_dir,'w');
		fwrite($fp, $img);
		fclose($fp);
		
		//给用户 增加金币100
		//$str_sql = sprintf("update t_userinfo set c_game_gold = c_game_gold + 100 where c_session_id = '%s'",
		//EscapeString($session_id));
		
		if($b_user_name == true)
		{
			$str_sql = sprintf("call proc_upload_head_img2('%s', '%s') ",
				EscapeString($user_name), EscapeString($session_id));
		}
		else
		{
			$str_sql = sprintf("call proc_upload_head_img('%s') ",
				EscapeString($session_id));
		}
		
//---
/*
fwrite($fptest, $str_sql . "\n");
fclose($fptest); 
*/
//---

		DBHelper::Exec($str_sql, $msg); 		

		echo "success";  //返回
	}
	catch(Exception $e)
	{
		echo $e->getMessage();
	}
}
 
 
 
// --------上传商品------------------------------------------------------ 
//--查询某种装扮的总数
function HttpAction_GetGoodsTotal()
{
	$type_1 = $_REQUEST["type_1"];
	$type_2 = $_REQUEST["type_2"];
	$type_3 = $_REQUEST["type_3"];
	$sex = $_REQUEST["sex"];
	
	$str_sql = sprintf("select count(*) as total_count from t_goods where type_1='%s' and type_2='%s' and type_3='%s'", 
		$type_1, $type_2, $type_3);

	// 2表示两者
	if ($sex != 2)
		$str_sql = sprintf("%s and sex = '%s';", $str_sql, $sex);

	DBHelper::QueryReturnJSON($str_sql);
}

//--查询某种商品的记录列表
function HttpAction_GetGoodsList()
{
	$type_1 = $_REQUEST["type_1"];
	$type_2 = $_REQUEST["type_2"];
	$type_3 = $_REQUEST["type_3"];
	$sex = $_REQUEST["sex"];

	$newPath = GetBeautifulPath($type_1); //存放文件的文件夹路径
	$page_index = GetRequest("page_index"); //当前查询的页码
	$per_page_count = GetRequest("per_page_count"); //每页行数
	$count = ($page_index - 1) * $per_page_count;

	$str_sql = sprintf("select *, '%s' as filepath from t_goods where type_1='%s' and type_2='%s' and type_3='%s'", 
		$newPath, $type_1, $type_2, $type_3);

	if ($sex != 2) { // 2表示男女都查
		$str_sql = sprintf("%s and sex = '%s'", $str_sql, $sex);
	}

	$str_sql = sprintf("%s limit %d, %d", $str_sql, $count, $per_page_count);

	DBHelper::QueryReturnJSON($str_sql);
}

//---获取提交的信息数组---
function _getGoodsParms($prefix)
{
	$parmsArray = array();
	
	$parmsArray["type_1"] = "";
	$parmsArray["type_2"] = "";
	$parmsArray["type_3"] = "";
	
	if(strlen($prefix) > 0)
		$prefix = $prefix . "_";
	
	$parmsArray["goods_id"] = GetRequest($prefix . "goods_id"); 				//商品ID
	$parmsArray["goods_name"] = GetRequest($prefix . "goods_name"); 			//商品名称
	$parmsArray["goods_name_view"] = GetRequest($prefix . "goods_name_view");	//商品名称2
	
	$parmsArray["level"] = GetRequest($prefix . "level"); 				//等级限制
	$parmsArray["sex"] = GetRequest($prefix . "sex"); 					//性别(0女, 1男)
	$parmsArray["z_1"] = GetRequest($prefix . "z_1"); 					//大层级(礼品大小, 0:小, 1:大)
	$parmsArray["z_2"] = GetRequest($prefix . "z_2"); 					//小层级
	$parmsArray["time"] = GetRequest($prefix . "time"); 				//有效时间(秒)
	$parmsArray["gold"] = GetRequest($prefix . "gold"); 				//金币价格
	$parmsArray["money"] = GetRequest($prefix . "money"); 				//比索价格
	$parmsArray["time1"] = GetRequest($prefix . "time1"); 				//有效时间1(秒)
	$parmsArray["gold1"] = GetRequest($prefix . "gold1"); 				//金币价格1
	$parmsArray["money1"] = GetRequest($prefix . "money1"); 			//比索价格1
	$parmsArray["time2"] = GetRequest($prefix . "time2"); 				//有效时间2(秒)
	$parmsArray["gold2"] = GetRequest($prefix . "gold2"); 				//金币价格2
	$parmsArray["money2"] = GetRequest($prefix . "money2"); 			//比索价格2
	$parmsArray["time3"] = GetRequest($prefix . "time3"); 				//有效时间3(秒)
	$parmsArray["gold3"] = GetRequest($prefix . "gold3"); 				//金币价格3
	$parmsArray["money3"] = GetRequest($prefix . "money3"); 			//比索价格3
	$parmsArray["charm"] = GetRequest($prefix . "charm"); 				//加魅力
	$parmsArray["courage"] = GetRequest($prefix . "courage"); 			//加勇气
	$parmsArray["power"] = GetRequest($prefix . "power"); 				//加体力
	$parmsArray["energy"] = GetRequest($prefix . "energy"); 			//加精力(人缘)
	$parmsArray["quality"] = GetRequest($prefix . "quality"); 			//加人品
	$parmsArray["assets"] = GetRequest($prefix . "assets"); 			//加资产(加金币)
	$parmsArray["is_new"] = GetRequest($prefix . "is_new"); 			//是否新品(0为新 1:旧)
	$parmsArray["is_sell"] = GetRequest($prefix . "is_sell"); 			//是否可售(0为不可售 1:可售)
	$parmsArray["is_inlay"] = GetRequest($prefix . "is_inlay"); 		//是否拥有镶嵌功能(0:不允许 1:允许)
	$parmsArray["inlay_id"] = GetRequest($prefix . "inlay_id"); 		//默认镶嵌的商品ID(0表示无默认)
	$parmsArray["total"] = GetRequest($prefix . "total"); 				//库存数量(限量 -1:不限制)
	$parmsArray["limit_time"] = GetRequest($prefix . "limit_time"); 	//可使用时间(秒) -1:不限制
	$parmsArray["limit_count"] = GetRequest($prefix . "limit_count"); 	//可使用次数，-1:不限制
	//$parmsArray["uptime"] = GetRequest($prefix . "uptime"); 			//上传时间
	$parmsArray["remark"] = GetRequest($prefix . "remark"); 			//备注(商品描述)
	$parmsArray["order_index"] = GetRequest($prefix . "order_index"); 	//排序字段
	$parmsArray["gift_goods_list"] = GetRequest($prefix . "gift_goods_list"); 			//子商品(等级礼包里包含的商品)
	
	return $parmsArray;
}
 
function _insert_goods($parmsArray, &$msg = null)
{
	// 不存在， insert
	$str_sql = sprintf("insert into t_goods(goods_name, goods_name_view, type_1, type_2, type_3, level, sex, z_1, z_2, 
		`time`, gold, money, time1, gold1, money1, time2, gold2, money2, time3, gold3, money3, 
		charm, courage, power, energy, quality, assets, 
		is_new, is_sell, is_inlay, inlay_id, total, limit_time, limit_count, uptime,edittime, remark, gift_goods_list, order_index) 
		values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 
		'%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s',
		'%s', '%s', '%s', '%s','%s', '%s', 
		'%s', '%s', '%s', '%s','%s', '%s', '%s', now(),now(), '%s', '%s', '%s')", 
	EscapeString($parmsArray["goods_name"]),		//商品名称 
	EscapeString($parmsArray["goods_name_view"]),	//商品名称2 
	EscapeString($parmsArray["type_1"]),   			//1级类 
	EscapeString($parmsArray["type_2"]),   			//2级类 
	EscapeString($parmsArray["type_3"]),   			//3级类 
	EscapeString($parmsArray["level"]),   			//等级限制 
	EscapeString($parmsArray["sex"]),   			//性别(0女, 1男) 
	EscapeString($parmsArray["z_1"]),   			//大层级(礼品大小, 0:小, 1:大) 
	EscapeString($parmsArray["z_2"]),   			//小层级 
	EscapeString($parmsArray["time"]),   	//有效时间(秒) 
	EscapeString($parmsArray["gold"]),   	//金币价格 
	EscapeString($parmsArray["money"]),   	//比索价格 
	EscapeString($parmsArray["time1"]),   	//有效时间1(秒) 
	EscapeString($parmsArray["gold1"]),   	//金币价格1 
	EscapeString($parmsArray["money1"]), 	//比索价格1 
	EscapeString($parmsArray["time2"]),   	//有效时间2(秒) 
	EscapeString($parmsArray["gold2"]),   	//金币价格2 
	EscapeString($parmsArray["money2"]), 	//比索价格2 
	EscapeString($parmsArray["time3"]),   	//有效时间3(秒) 
	EscapeString($parmsArray["gold3"]),   	//金币价格3 
	EscapeString($parmsArray["money3"]), 	//比索价格3 
	EscapeString($parmsArray["charm"]),   	//加魅力 
	EscapeString($parmsArray["courage"]),	//加勇气 
	EscapeString($parmsArray["power"]),   	//加体力 
	EscapeString($parmsArray["energy"]),   	//加精力(人缘) 
	EscapeString($parmsArray["quality"]), 	//加人品 
	EscapeString($parmsArray["assets"]),   	//加资产(加金币) 
	EscapeString($parmsArray["is_new"]),  			//是否新品(0为新 1:旧) 
	EscapeString($parmsArray["is_sell"]),   		//是否可售(0为不可售 1:可售) 
	EscapeString($parmsArray["is_inlay"]),   		//是否拥有镶嵌功能(0:不允许 1:允许) 
	EscapeString($parmsArray["inlay_id"]),   		//默认镶嵌的商品ID(0表示无默认) 
	EscapeString($parmsArray["total"]),   			//库存数量(限量 -1:不限制) 
	EscapeString($parmsArray["limit_time"]),   		//可使用时间(秒) -1:不限制 
	EscapeString($parmsArray["limit_count"]),   	//可使用次数，-1:不限制
	EscapeString($parmsArray["remark"]),   			//备注(商品描述)
	EscapeString($parmsArray["gift_goods_list"]),   //子商品(等级礼包里包含的商品)
	EscapeString($parmsArray["order_index"])   		//排序字段
	); 
	 
	return DBHelper::InsertReturnID($str_sql, $msg);
}

function _update_goods($parmsArray, &$msg = null)
{
	// 存在 则修改数据
	$str_sql = sprintf("update t_goods set goods_name='%s', goods_name_view='%s', type_1='%s', type_2='%s', type_3='%s', 
		level='%s', sex='%s', z_1='%s', z_2='%s', time='%s', gold='%s', money='%s', time1='%s', 
		gold1='%s', money1='%s', time2='%s', gold2='%s', money2='%s', time3='%s', gold3='%s', money3='%s', 
		charm='%s', courage='%s', power='%s', energy='%s', quality='%s', assets='%s', 
		is_new='%s', is_sell='%s', is_inlay='%s', inlay_id='%s', 
		total='%s', limit_time='%s', limit_count='%s', edittime=now(), remark='%s', gift_goods_list='%s', order_index='%s' 
		where goods_id='%s';", 
	EscapeString($parmsArray["goods_name"]),		//商品名称 
	EscapeString($parmsArray["goods_name_view"]),	//商品名称2
	EscapeString($parmsArray["type_1"]),   			//1级类 
	EscapeString($parmsArray["type_2"]),   			//2级类 
	EscapeString($parmsArray["type_3"]),   			//3级类 
	
	EscapeString($parmsArray["level"]),   		//等级限制 
	EscapeString($parmsArray["sex"]),   		//性别(0女, 1男) 
	EscapeString($parmsArray["z_1"]),   		//大层级(礼品大小, 0:小, 1:大) 
	EscapeString($parmsArray["z_2"]),   		//小层级 
	EscapeString($parmsArray["time"]),   	//有效时间(秒) 
	EscapeString($parmsArray["gold"]),   	//金币价格 
	EscapeString($parmsArray["money"]),   	//比索价格 
	EscapeString($parmsArray["time1"]),   	//有效时间1(秒) 
	EscapeString($parmsArray["gold1"]),   	//金币价格1 
	EscapeString($parmsArray["money1"]), 	//比索价格1 
	EscapeString($parmsArray["time2"]),   	//有效时间2(秒) 
	EscapeString($parmsArray["gold2"]),   	//金币价格2 
	EscapeString($parmsArray["money2"]), 	//比索价格2 
	EscapeString($parmsArray["time3"]),   	//有效时间3(秒) 
	EscapeString($parmsArray["gold3"]),   	//金币价格3 
	EscapeString($parmsArray["money3"]), 	//比索价格3 
	EscapeString($parmsArray["charm"]),   	//加魅力 
	EscapeString($parmsArray["courage"]),  	//加勇气 
	EscapeString($parmsArray["power"]),   	//加体力 
	EscapeString($parmsArray["energy"]),   	//加精力(人缘) 
	EscapeString($parmsArray["quality"]),  	//加人品 
	EscapeString($parmsArray["assets"]),   	//加资产(加金币) 
	EscapeString($parmsArray["is_new"]),   			//是否新品(0为新 1:旧) 
	EscapeString($parmsArray["is_sell"]),   		//是否可售(0为不可售 1:可售) 
	EscapeString($parmsArray["is_inlay"]),   		//是否拥有镶嵌功能(0:不允许 1:允许) 
	EscapeString($parmsArray["inlay_id"]),   		//默认镶嵌的商品ID(0表示无默认) 
	EscapeString($parmsArray["total"]),   			//库存数量(限量 -1:不限制) 
	EscapeString($parmsArray["limit_time"]),   		//可使用时间(秒) -1:不限制 
	EscapeString($parmsArray["limit_count"]),   	//可使用次数，-1:不限制
	EscapeString($parmsArray["remark"]),   			//备注(商品描述)
	EscapeString($parmsArray["gift_goods_list"]),   //子商品(等级礼包里包含的商品)
	EscapeString($parmsArray["order_index"]),   	//排序字段
	EscapeString($parmsArray["goods_id"])   		//商品ID 
	); 	
	return DBHelper::Exec($str_sql, $msg);
}

//--上传商品
function HttpAction_UpdateGoods()
{	
	$type_1 = $_REQUEST["type_1"]; 			//1级类
	$type_2 = $_REQUEST["type_2"]; 			//2级类
	$type_3 = $_REQUEST["type_3"]; 			//3级类
	
	$prefix = "";
	$parmsArray  = _getGoodsParms($prefix);		//获取提交的信息数组
	$parmsArray["type_1"] = $type_1; 			//1级类
	$parmsArray["type_2"] = $type_2; 			//2级类
	$parmsArray["type_3"] = $type_3; 			//3级类
	$goods_id =  $parmsArray["goods_id"];
	$sex = $parmsArray["sex"];
	
	$str_sql = sprintf("select sex, goods_id from t_goods where goods_id = '%s'", $goods_id);
	
	$bExec = true;
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) 
	{
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	if (count($rsArray) > 0) 
	{	//存在，则修改
		$res = _update_goods($parmsArray, $msg);
		$bExec = ($res != - 1);	
		
		$genderOld = $rsArray[0]["sex"];
		if ($bExec && $sex != $genderOld)
		{	// 修改了性别, 修改文件名
			EditBeautifulFileName($type_1, $goods_id, $genderOld, $goods_id, $sex); 	
		}
	} 
	else 
	{
		//不存在, 则新增
		$goods_id = _insert_goods($parmsArray, $msg);
		$bExec = ($goods_id != - 1);
	}

	if (!$bExec) {
		PrintMsgToHTML("编辑失败: " . $msg);
		return;
	}
	
	//保存上传文件
	$finfo_0 = "file_0: ";
	$finfo_1 = "file_1: ";
	$finfo_2 = "file_2: ";
	$finfo_3 = "file_3: ";
	$finfo_4 = "file_4: ";
	
	$fileInfoArray = GetBeautifulFileInfo($type_1, $type_2, $type_3, $goods_id, $sex); //文件路径信息
	$finfo_0 .= UploadFile("file_0", $fileInfoArray[0]["path"], $fileInfoArray[0]["name"]);	 
	$finfo_1 .= UploadFile("file_1", $fileInfoArray[1]["path"], $fileInfoArray[1]["name"]); 
	$finfo_2 .= UploadFile("file_2", $fileInfoArray[2]["path"], $fileInfoArray[2]["name"]);
	$finfo_3 .= UploadFile("file_3", $fileInfoArray[3]["path"], $fileInfoArray[3]["name"]);
	$finfo_4 .= UploadFile("file_4", $fileInfoArray[4]["path"], $fileInfoArray[4]["name"]);

	PrintMsgToHTML("编辑成功", $finfo_0, $finfo_1, $finfo_2, $finfo_3, $finfo_4);
}

 //--获取商品的一条记录
function HttpAction_GetGoodsInfo()
{
	$type_1 = $_REQUEST["type_1"];
	$type_2 = $_REQUEST["type_2"];
	$goods_id = $_REQUEST["goods_id"];
	$sex = $_REQUEST["sex"];
	
	
	$str_sql = sprintf("select * from t_goods where goods_id = '%s'", $goods_id); 
	$rsArray = DBHelper::Query($str_sql, $msg);
	
	if ($rsArray == null)
		return false;	 
	if (count($rsArray) <= 0)
		return false;  
		
	$type_1 = $rsArray[0]["type_1"];
	$type_2 = $rsArray[0]["type_2"]; 
	$sex = $rsArray[0]["sex"];  
	
	$tmpArray = JudgeFileName($type_1, $type_2, $goods_id, $sex);  //判断文件是否物理存在
	
	$file_0 = $tmpArray["file_0"];
	$file_1 = $tmpArray["file_1"];
	$file_2 = $tmpArray["file_2"];
	$file_3 = $tmpArray["file_3"];
	$file_4 = $tmpArray["file_4"];

	$newPath = GetBeautifulPath($type_1); //存放文件的文件夹路径
	$str_sql = sprintf("select *, '%s' as filepath, '%s' as file_0, '%s' as file_1, '%s' as file_2, '%s' as file_3, '%s' as file_4 from t_goods where goods_id = %s",
	    $newPath, $file_0, $file_1, $file_2, $file_3, $file_4, EscapeString($goods_id));
		
	DBHelper::QueryReturnJSON($str_sql);
}

//--删除一条装扮记录
function HttpAction_DeleteGoods()
{
	$goods_id = $_REQUEST["goods_id"]; 
	$bExec = _deleteOneGoods($goods_id, &$msg); //删除某条商品记录
	$strReturn = "删除成功";
	if (!$bExec)
		$strReturn = "错误：" . $msg;

	ReturnJSONMsg($strReturn);
} 

//--删除某条商品记录
function _deleteOneGoods($goods_id, &$msg)
{
	$str_sql = sprintf("select goods_id, sex, type_1, type_2, type_3 from t_goods where goods_id = '%s'", $goods_id); 
	$rsArray = DBHelper::Query($str_sql, $msg);
	
	if ($rsArray == null)
		return false;		
	if (count($rsArray) <= 0)
		return false; 
		
	// 删除数据库
	$str_sql = sprintf("delete from t_goods where goods_id = '%s'", $goods_id);
	if (DBHelper::Exec($str_sql, $msg) == - 1)
		return false;
			 
	// 删除文件
	$sex = $rsArray[0]["sex"]; //性别信息
	$type_1 = $rsArray[0]["type_1"];
	$type_2 = $rsArray[0]["type_2"];
	$type_3 = $rsArray[0]["type_3"];
	$fileInfoArray = GetBeautifulFileInfo($type_1, $type_2, $type_3, $goods_id, $sex); //文件信息
	DeleteFileArray($fileInfoArray); 
	
	return true;
	
}

//--设置某商品新旧标记
function HttpAction_SetGoodsIsNew()
{
	$goods_id = $_REQUEST["goods_id"];
	$str_sql = sprintf("select goods_id, is_new from t_goods where goods_id = '%s'", $goods_id);

	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == null) {
		ReturnJSONErrorMsg("错误：" . $msg);
		return;
	}
	if (count($rsArray) <= 0) {
		ReturnJSONErrorMsg("数据不存在...");
		return;
	}
	// 设置
	$is_new = $rsArray[0]["is_new"];
	$tmpIsNew = $is_new == 0 ? 1: 0;
	$str_sql = sprintf("update t_goods set is_new = '%s' where goods_id = '%s'", $tmpIsNew, $goods_id);

	DBHelper::ExecReturnJSON($str_sql);
} 

//--设置某商品可售标记
function HttpAction_SetGoodsIsSell()
{
	$goods_id = $_REQUEST["goods_id"];

	$str_sql = sprintf("select goods_id, is_sell from t_goods where goods_id = '%s'", $goods_id);

	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == null) {
		ReturnJSONErrorMsg("错误：" . $msg);
		return;
	}
	if (count($rsArray) <= 0) {
		ReturnJSONErrorMsg("数据不存在...");
		return;
	}
	// 设置
	$is_sell = $rsArray[0]["is_sell"];
	$tmpIsSell = $is_sell == 0 ? 1: 0;
	$str_sql = sprintf("update t_goods set is_sell = '%s' where goods_id = '%s'", $tmpIsSell, $goods_id);

	DBHelper::ExecReturnJSON($str_sql);
} 


// ------------------套装-----------------------------
//--查询套装总数---------
function HttpAction_GetDressPacketTotal()
{
	$type_3 = $_REQUEST["type_3"];
	$sex = $_REQUEST["sex"];
	$str_sql = sprintf("select count(*) as total_count from t_goods_dress where type_3='%s'", $type_3);

	// 2表示男女都查
	if ($sex != 2) {
		$str_sql = sprintf("%s and sex = '%s'", $str_sql, $sex);
	}

	DBHelper::QueryReturnJSON($str_sql);
}

//--查询某type_3类别的套装列表--
function HttpAction_GetDressPacketList()
{
	$page_index = GetRequest("page_index"); //当前查询的页码
	$per_page_count = GetRequest("per_page_count"); //每页行数
	$count = ($page_index - 1) * $per_page_count;

	$type_3 = $_REQUEST["type_3"];
	$sex = $_REQUEST["sex"];
	
	$type_1 = "clothing"; 
	$msg = "";
	
	$returnArray = array();

	$str_sql = sprintf("select * from t_goods_dress where type_3='%s'", EscapeString($type_3));
	
	// 2表示两者
	if ($sex != 2)
		$str_sql = sprintf("%s and sex = '%s'", $str_sql, $sex);

	$str_sql = sprintf("%s limit %d,%d", $str_sql, $count, $per_page_count);
	
	$dressArray = DBHelper::Query($str_sql, $msg);
	if($dressArray == -1)
	{
		ReturnJSONErrorMsg($msg);
		return false;
	}
	if(count($dressArray) == 0)
	{
		$retMsg = sprintf("套装ID[%s]不存在, error:%s", $id, $msg);
		ReturnJSONErrorMsg($retMsg);
		return;
	}
	
	$newPath = GetBeautifulPath($type_1); //存放文件的文件夹路径
	foreach($dressArray as $key => $romItem)
	{
		$dress = $romItem["dress"];
		$dress_goods_array = __get_dress_goods($dress); //从套装信息表dress字段 解析出商品信息成数组 {type_2=>goods_id}
		
		foreach($dress_goods_array as $type_2 => $goods_id)  //查询套装子商品信息
		{ 
			$str_sql_goods = sprintf("select goods_id, goods_name, goods_name_view, money, gold, total  from t_goods where goods_id = %s", EscapeString($goods_id)); 
			$rArray = DBHelper::Query($str_sql_goods, $msg);
			if($rArray != -1)
			{
				$romItem[$type_2."_goods_id"] = $rArray[0]["goods_id"];					//商品信息表
				$romItem[$type_2."_goods_name"] = $rArray[0]["goods_name"];				//商品信息表
				$romItem[$type_2."_goods_name_view"] = $rArray[0]["goods_name_view"];	//商品信息表
				
				$romItem[$type_2."_money"] = $rArray[0]["money"];		//商品信息表
				$romItem[$type_2."_gold"] = $rArray[0]["gold"];			//商品信息表
				$romItem[$type_2."_total"] = $rArray[0]["total"];		//商品信息表
				 
				$romItem["filepath"] = $newPath;	//商品图片存放路径
			}
		}
		$returnArray[] = $romItem;
	}
	ReturnJSONFromResultArray($returnArray, "", "");
}


function __create_dress($goods_id, $type_2)  //构建套装表dress字段 单条商品  {'id':1001, 'type_2':'cost'}
{
	$tmpStr = "";
	if($goods_id > 0)
	{
		$tmpStr = sprintf('{"id":%s,"type_2":"%s"}', $goods_id, $type_2);
		$tmpStr .= ", ";
	}
	return $tmpStr;
}

function __get_dress_goods($dress)		//构建套装表dress字段 解析商品信息成数组 {type_2=>goods_id}
{
	$tmpArray = array();
	$dress_info_array = json_decode2($dress);  //套装表， 子商品信息 
	for($i = 0; $i < count($dress_info_array); $i++)
	{
		$obj = $dress_info_array[$i]; 
		if($obj)
			$tmpArray[$obj->type_2] = $obj->id;
	}
	return $tmpArray;
}

// --套装--上传--套装-----
function HttpAction_UpdateGoodsDressPacket()
{
	$type_1 = "clothing";
	$id = $_REQUEST["id"];
	$sex = $_REQUEST["sex"];
	$type_3 = $_REQUEST["type_3"];
	$level = $_REQUEST["level"];
	$is_new = $_REQUEST["is_new"];
	$is_sell = $_REQUEST["is_sell"];

	$str_sql = sprintf("select id, sex from t_goods_dress where id = '%s'", $id);

	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) {
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	// 上衣插入/修改
	$type_2 = "cost";
	$cost_returnArray = HttpAction_UpdateDressPacketType2($type_2, $msg);
	$cost_id = $cost_returnArray[0];
	$cost_charm = $cost_returnArray[1];
	if ($cost_id == - 1) {
		PrintMsgToHTML("编辑上衣信息失败...:". $msg);
		return;
	}
	// 裤子插入/修改
	$type_2 = "trousers";
	$trousers_returnArray = HttpAction_UpdateDressPacketType2($type_2, $msg);
	$trousers_id = $trousers_returnArray[0];
	$trousers_charm = $trousers_returnArray[1];
	if ($trousers_id == - 1) {
		PrintMsgToHTML("编辑裤子信息失败...:". $msg);
		return;
	}

	// 连衣裙插入/修改
	$type_2 = "skirt";
	$skirt_returnArray = HttpAction_UpdateDressPacketType2($type_2, $msg);
	$skirt_id = $skirt_returnArray[0];
	$skirt_charm = $skirt_returnArray[1];
	if ($skirt_id == - 1) {
		PrintMsgToHTML("编辑连衣裙信息失败...:". $msg);
		return;
	}
	
	// 外套插入/修改
	$type_2 = "coat";
	$coat_returnArray = HttpAction_UpdateDressPacketType2($type_2, $msg);
	$coat_id = $coat_returnArray[0];
	$coat_charm = $coat_returnArray[1];
	if ($coat_id == - 1) {
		PrintMsgToHTML("编辑外套信息失败...:". $msg);
		return;
	}
	
	//构建套装信息 //[{"id":1001,"type_2":"coat"},{"id":1022,"type_2":"trousers"}]
	$dressTmp = "";
	$dressTmp .= __create_dress($cost_id, "cost");
	$dressTmp .= __create_dress($trousers_id, "trousers");
	$dressTmp .= __create_dress($skirt_id, "skirt");
	$dressTmp .= __create_dress($coat_id, "coat");
	$dressTmp = rtrim($dressTmp);
	if(strlen($dressTmp) > 1)
	{
		$dressTmp = substr($dressTmp, 0, strlen($dressTmp) - 1);
	}	
	$dress = sprintf("[%s]", $dressTmp); 
	$order_index = $cost_charm + $trousers_charm + $skirt_charm + $coat_charm;
						   
	if (count($rsArray) > 0) {
		$genderOld = $rsArray[0]["sex"];
		if ($sex != $genderOld) { // 修改了性别, 修改文件名
			EditBeautifulFileName($type_1, $skirt_id, $genderOld, $skirt_id, $sex);
			EditBeautifulFileName($type_1, $cost_id, $genderOld, $cost_id, $sex);
			EditBeautifulFileName($type_1, $trousers_id, $genderOld, $trousers_id, $sex);
			EditBeautifulFileName($type_1, $coat_id, $genderOld, $coat_id, $sex);
		}
			
		// 存在， 则修改
		$str_sql = sprintf("update t_goods_dress set sex='%s', type_3='%s',
		level='%s', is_new='%s', is_sell='%s', dress='%s', order_index='%s' where id='%s'",
		EscapeString($sex),
		EscapeString($type_3),
		EscapeString($level),
		EscapeString($is_new),
		EscapeString($is_sell),
		EscapeString($dress),
		EscapeString($order_index),
		EscapeString($id)
		);
		
	} else {
		// 不存在， 则套装表插入
		$str_sql = sprintf("insert into t_goods_dress(sex, type_3, level, is_new, is_sell, dress, order_index) 
						values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
		EscapeString($sex),
		EscapeString($type_3),
		EscapeString($level),
		EscapeString($is_new),
		EscapeString($is_sell),
		EscapeString($dress),
		EscapeString($order_index)
		);
	}
	DBHelper::ExecAndPrintMsg($str_sql);
}

// --套装--上传--type2--
function HttpAction_UpdateDressPacketType2($type_2, &$msg)
{	
	$type_1 = "clothing"; 					//1级类 
	$type_3 = $_REQUEST["type_3"]; 			//3级类
	$sex = $_REQUEST["sex"];
	$level = $_REQUEST["level"];
	$is_new = $_REQUEST["is_new"];
	$is_sell = $_REQUEST["is_sell"];
	
	$prefix = $type_2;   						//前缀
	$parmsArray = _getGoodsParms($prefix);		//获取提交的信息数组
	$parmsArray["type_1"] = $type_1; 			//1级类
	$parmsArray["type_2"] = $type_2; 			//2级类
	$parmsArray["type_3"] = $type_3; 			//3级类 
	$parmsArray["sex"] = $sex;
	$parmsArray["level"] = $level;
	$parmsArray["is_new"] = $is_new;
	$parmsArray["is_sell"] = $is_sell;
	
	$goods_id =  $parmsArray["goods_id"];	
	
	$bIsUpload  = isset($_REQUEST[$prefix . "_check"]); 	//是否允许上传 
	$bExec = true;
	
	$str_sql = sprintf("select sex, goods_id from t_goods where goods_id = '%s'", $goods_id);
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) //查询出错
		return -1;  
	
	$bExistRow = count($rsArray) > 0; //DB是否存在记录
	if (!$bExistRow && !$bIsUpload) //不存在 也不允许上传 
		return 0; 
		
	if ($bExistRow && !$bIsUpload)// 已存在记录， 但不允许上传 ， 则删除原有的记录及文件 
		return _deleteOneGoods($goods_id, $msg) ? 0 : -1; 
		
	if ($bExistRow) 
	{	//存在，则修改		
		$res = _update_goods($parmsArray, $msg);
		$bExec = ($res != - 1);	
		
		$genderOld = $rsArray[0]["sex"];
		if ($bExec && $sex != $genderOld) // 修改了性别, 修改文件名 
			EditBeautifulFileName($type_1, $goods_id, $genderOld, $goods_id, $sex);  
	}  
	else 
	{
		//不存在, 则新增
		$goods_id = _insert_goods($parmsArray, $msg);
		$bExec = ($goods_id != - 1);
	}

	if (!$bExec) 
		return -1; 
	
	//保存上传文件
	$finfo_0 = "file_0: ";
	$finfo_1 = "file_1: ";
	$finfo_2 = "file_2: ";
	$finfo_3 = "file_3: ";
	$finfo_4 = "file_4: ";
	
	$fileInfoArray = GetBeautifulFileInfo($type_1, $type_2, $type_3, $goods_id, $sex); //文件路径信息
	$finfo_0 .= UploadFile($prefix."_file_0", $fileInfoArray[0]["path"], $fileInfoArray[0]["name"]);	 
	$finfo_1 .= UploadFile($prefix."_file_1", $fileInfoArray[1]["path"], $fileInfoArray[1]["name"]); 
	$finfo_2 .= UploadFile($prefix."_file_2", $fileInfoArray[2]["path"], $fileInfoArray[2]["name"]);
	$finfo_3 .= UploadFile($prefix."_file_3", $fileInfoArray[3]["path"], $fileInfoArray[3]["name"]);
	$finfo_4 .= UploadFile($prefix."_file_4", $fileInfoArray[4]["path"], $fileInfoArray[4]["name"]);

	PrintMsgToHTML("编辑成功", $finfo_0, $finfo_1, $finfo_2, $finfo_3, $finfo_4);
	 
	
	$returnArray = array();
	$returnArray[] = $goods_id;				//服装ID
	$returnArray[] = $parmsArray["charm"];  //服装魅力值
	return $returnArray;
} 

//--套装---查询某条套装记录--
function HttpAction_getGoodsDressInfo()
{
	$type_1 = "clothing";
	$id = $_REQUEST["id"];
	$msg = "";
	
	$returnArray = array();
	
	$str_sql = sprintf("select * from t_goods_dress where id = %s",  EscapeString($id));	
	$dressArray = DBHelper::Query($str_sql, $msg);
	if($dressArray == -1)
	{
		ReturnJSONErrorMsg($msg);
		return false;
	}
	if(count($dressArray) == 0)
	{
		$retMsg = sprintf("套装ID[%s]不存在, error:%s", $id, $msg);
		ReturnJSONErrorMsg($retMsg);
		return;
	}
	
	$sex = $dressArray[0]["sex"];
	$dress = $dressArray[0]["dress"];
	$returnArray["dress"] = $dressArray; 						//套装信息表	
	
	$dress_goods_array = __get_dress_goods($dress); //从套装信息表dress字段 解析出商品信息成数组 {type_2=>goods_id}
	
	foreach($dress_goods_array as $type_2 => $goods_id)  //查询套装子商品信息
	{ 
		$tmpArray = JudgeFileName($type_1, $type_2, $goods_id, $sex);  //判断文件是否物理存在
	
		$file_0 = $tmpArray["file_0"];
		$file_1 = $tmpArray["file_1"];
		$file_2 = $tmpArray["file_2"];
		$file_3 = $tmpArray["file_3"];
		$file_4 = $tmpArray["file_4"];

		$newPath = GetBeautifulPath($type_1); //存放文件的文件夹路径
		$str_sql_goods = sprintf("select *, '%s' as filepath, '%s' as file_0, '%s' as file_1, '%s' as file_2, '%s' as file_3, '%s' as file_4 from t_goods where goods_id = %s",
			$newPath, $file_0, $file_1, $file_2, $file_3, $file_4, EscapeString($goods_id));
			 	
		//$str_sql_goods = sprintf("select * from t_goods  where goods_id = %s ", $goods_id); 
		$rArray = DBHelper::Query($str_sql_goods, $msg);
		if($rArray != -1)
			$returnArray[$type_2] = $rArray;	//商品信息表
	}	
	ReturnJSONFromResultArray($returnArray, "", "");
}

// --套装--删除-------
function HttpAction_DeleteGoodsDress()
{
	$id = $_REQUEST["id"];
	$str_sql = sprintf("select id, sex, dress from t_goods_dress where id = '%s'", $id);
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == -1)
	{
		ReturnJSONErrorMsg("错误：" . $msg);
		return;
	}
	if (count($rsArray) <= 0) {
		ReturnJSONErrorMsg("数据不存在...");
		return;
	} 
	
	//[{"id":1001,"type_2":"coat"},{"id":1022,"type_2":"trousers"}]	
	$dress_goods_array = __get_dress_goods($rsArray[0]["dress"]); //从套装信息表dress字段 解析出商品信息成数组 {type_2=>goods_id}
	foreach($dress_goods_array as $type_2 => $goods_id) 
	{ 		
		_deleteOneGoods($goods_id, $msg);	//删除套装商品
	}

	$str_sql = sprintf("delete from t_goods_dress where id = %s", $id); //删除套装信息
	DBHelper::ExecReturnJSON($str_sql);
}

// --套装--设置某商品新旧标记-------
function HttpAction_SetGoodsDressIsNew()  
{
	$goods_id = $_REQUEST["id"];
	$str_sql = sprintf("select id, is_new from t_goods_dress where id = '%s'", $goods_id);

	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == null) {
		ReturnJSONErrorMsg("错误：" . $msg);
		return;
	}
	if (count($rsArray) <= 0) {
		ReturnJSONErrorMsg("数据不存在...");
		return;
	}
	// 设置
	$is_new = $rsArray[0]["is_new"];
	$tmpIsNew = $is_new == 0 ? 1: 0;
	$str_sql = sprintf("update t_goods_dress set is_new = '%s' where id = '%s'", $tmpIsNew, $goods_id);
	 
	DBHelper::ExecReturnJSON($str_sql);
}

// --套装--设置某商品可售标记-------
function HttpAction_SetGoodsDressIsSell()  
{
	$goods_id = $_REQUEST["id"];
	$str_sql = sprintf("select id, is_new, is_sell from t_goods_dress where id = '%s'", $goods_id);

	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == null) {
		ReturnJSONErrorMsg("错误：" . $msg);
		return;
	}
	if (count($rsArray) <= 0) {
		ReturnJSONErrorMsg("数据不存在...");
		return;
	}
	// 设置
	$is_sell = $rsArray[0]["is_sell"];
	$tmpIsNew = $is_sell == 0 ? 1: 0;
	$str_sql = sprintf("update t_goods_dress set is_sell = '%s' where id = '%s'", $tmpIsNew, $goods_id);
	
	DBHelper::ExecReturnJSON($str_sql);
}
 
 
 //--编辑套装的排序字段(为所有子服装的魅力值)--
function HttpAction_EditAllDressPacketOrderIndex()
{  
	$type_1 = "clothing"; 
	$msg = "";
	
	$str_sql = sprintf("select * from t_goods_dress "); 
	
	$dressArray = DBHelper::Query($str_sql, $msg);
	if($dressArray == -1)
	{
		ReturnJSONErrorMsg($msg);
		return false;
	}
	if(count($dressArray) == 0)
	{
		$retMsg = sprintf("套装数据不存在, error:%s", $msg);
		ReturnJSONErrorMsg($retMsg);
		return;
	}
	$editCount = 0;
	foreach($dressArray as $key => $romItem)
	{
		$dress_id = $romItem["id"];	//套装ID
		$order_index = 0;			//套装排序字段(所有子服装魅力值)
		$dress = $romItem["dress"]; //套装信息
		$dress_goods_array = __get_dress_goods($dress); //从套装信息表dress字段 解析出商品信息成数组 {type_2=>goods_id}
		
		foreach($dress_goods_array as $type_2 => $goods_id)  //查询套装子商品信息
		{ 
			$str_sql_goods = sprintf("select goods_id, charm from t_goods where goods_id = %s", EscapeString($goods_id)); 
			$rArray = DBHelper::Query($str_sql_goods, $msg);
			if($rArray != -1)
			{
				$order_index += $rArray[0]["charm"];	//商品信息表魅力值
			} 
		}
		//则修改排序字段
		$str_sql = sprintf("update t_goods_dress set order_index='%s' where id='%s'", 
		EscapeString($order_index),
		EscapeString($dress_id)
		);  
		DBHelper::Exec($str_sql, $msg);
		$editCount += 1; 
	}
	
	$tmpMsg =  sprintf("套装数量[%s], 修改数量[%s]", count($dressArray), $editCount);
	ReturnJSONMsg($tmpMsg);
}
 
 
 
// ---------查询类别信息-------------------------
function HttpAction_GetGoodsType1()
{
	ReturnJSONFromArray($GLOBALS["goods_type_1"], "", "");
} 

function HttpAction_GetGoodsType2()
{ 
	$typeName = $_REQUEST["typeName"];
	$tmpName = $typeName . "_type2";
	ReturnJSONFromArray($GLOBALS[$tmpName], "", "");
}

function HttpAction_GetGoodsType3()
{ 
	$typeName_1 = $_REQUEST["typeName_1"];
	$typeName = $_REQUEST["typeName"];
	
	$tmpName = $typeName_1 ;
	if($typeName_1 == "props")
	{
		$tmpName .= "_" . $typeName;
	}
	$tmpName .= "_type3";
	
	ReturnJSONFromArray($GLOBALS[$tmpName], "", "");
}


//根据等级修改金币魅力等-----
function HttpAction_edit_auto_goods_info()
{
	$goods_id = $_REQUEST["goods_id"];
	$level = $_REQUEST["level"];
	$goods_name = $_REQUEST["goods_name"];
	$is_checkbox_money = $_REQUEST["is_checkbox_money"];

	//--获取等级
	$str_sql = sprintf("select type_2, type_3 from t_goods where goods_id = '%s'", $goods_id);
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == -1)
	{
		ReturnJSONErrorMsg("错误：" . $msg);
		return;
	}
	if (count($rsArray) <= 0) {
		ReturnJSONErrorMsg("数据不存在...");
		return;
	} 
	
	//汇率
	$auto_exchange_rate_money_to_gold = GetConfInfo("auto_exchange_rate_money_to_gold"); //汇率 1比索=20金币
	
	//续费价：
	$auto_price_scale_1 = GetConfInfo("auto_price_scale_1");			//10 续费7天价为原价的10%													
	$auto_price_scale_2 = GetConfInfo("auto_price_scale_2");			//20 续费30天价为原价的20%													
	$auto_price_scale_3 = GetConfInfo("auto_price_scale_3");			//30 续费180天价为原价的50%													

	//商品时间
	$auto_goods_time = GetConfInfo("auto_goods_time");;			//有效期		30天（2592000秒）	
	$auto_goods_time_1 = GetConfInfo("auto_goods_time_1");;		//有效期1		7天（604800秒），原价10%	
	$auto_goods_time_2 = GetConfInfo("auto_goods_time_2");;  	//有效期2		30天（2592000秒），原价20%	
	$auto_goods_time_3 = GetConfInfo("auto_goods_time_3");;		//有效期3		180天（15552000秒），原价50%	
	
	//规则
	$auto_role_gold_money_array = GetConfInfo("auto_role_gold_money");
	$auto_role_charm_array = GetConfInfo("auto_role_charm");
	//ReturnJSONFromArray($auto_role_gold_money_array, "", "");return; 
	
	$tmpLevel = $level; 
	$type_2 = $rsArray[0]["type_2"];
	$type_3 = $rsArray[0]["type_3"];
	
	  $time = $auto_goods_time;        	// '有效时间(秒)',有效期		30天（2592000秒）
	  $gold = 0;        				// '金币价格', 
	  $money = 0;        				// '比索价格',
	  
	  $time1 = $auto_goods_time_1;      // '有效时间1(秒)',有效期1		7天（604800秒），原价10%
	  $gold1 = 0;        				// '金币价格1',
	  $money1 = 0;        				// '比索价格1',
	  
	  $time2 = $auto_goods_time_2;      // '有效时间2(秒)',有效期2		30天（2592000秒），原价20%	
	  $gold2 = 0;        				// '金币价格2',
	  $money2 = 0;        				// '比索价格2',
	  
	  $time3 = $auto_goods_time_3;      // '有效时间3(秒)',有效期3		180天（15552000秒），原价50%
	  $gold3 = 0;        				// '金币价格3',
	  $money3 = 0;        				// '比索价格3',
		
	  $charm = 0;        // '加魅力',*/
		
	if(!array_key_exists($type_2, $auto_role_gold_money_array) || !array_key_exists($type_2, $auto_role_charm_array))
	{
		ReturnJSONErrorMsg("type_2[$type_2]不存在规则里...");
		return;
	} 
	
	$strRoleMoney ="return $auto_role_gold_money_array[$type_2];";  
	$money = eval($strRoleMoney);
	//WriteLog("strRoleMoney:" . $strRoleMoney);
	//WriteLog("money:" . $money);
	
	$strRoleCharm ="return $auto_role_charm_array[$type_2];";  
	$charm = eval($strRoleCharm);
	//WriteLog("strRoleCharm:" . $strRoleCharm);
	//WriteLog("charm:" . $charm);
		
	if($is_checkbox_money == "0")  //选择的是金币
	{
		$gold = $money * $auto_exchange_rate_money_to_gold;
		$money = 0;
		
		$charm = $charm - 1;
		if($charm < 0)
			$charm = 0;
	} 
	  $gold1 = round($gold * $auto_price_scale_1 / 100);        				// '金币价格1', 原价10%
	  $money1 = round($money * $auto_price_scale_1 / 100);        				// '比索价格1', 原价10%
	  
	  $gold2 = round($gold * $auto_price_scale_2 / 100);        				// '金币价格2', 原价20%
	  $money2 = round($money * $auto_price_scale_2 / 100);        				// '比索价格2', 原价20%
	  
	  $gold3 = round($gold * $auto_price_scale_3 / 100);        				// '金币价格3',原价50%
	  $money3 = round($money * $auto_price_scale_3 / 100);        				// '比索价格3',原价50%
  	
	$str_sql = sprintf("update t_goods set  
	  `goods_name` = '%s' ,   `level` = '%s' ,        
	  `time` = '%s' ,   `gold` = '%s' ,   `money` = '%s' ,        
	  `time1` = '%s' ,  `gold1` = '%s' ,  `money1` = '%s' ,       
	  `time2` = '%s' ,  `gold2` = '%s' ,  `money2` = '%s' ,       
	  `time3` = '%s' ,  `gold3` = '%s' ,  `money3` = '%s' ,      
	  `charm` = '%s'     where goods_id='%s' ", 

		EscapeString($goods_name), // '商品名称', 
		EscapeString($level), // '等级限制',
		EscapeString($time), // '有效时间(秒)',
		EscapeString($gold), // '金币价格',
		EscapeString($money), // '比索价格',
		EscapeString($time1), // '有效时间1(秒)',
		EscapeString($gold1), // '金币价格1',
		EscapeString($money1), // '比索价格1',
		EscapeString($time2), // '有效时间2(秒)',
		EscapeString($gold2), // '金币价格2',
		EscapeString($money2), // '比索价格2',
		EscapeString($time3), // '有效时间3(秒)',
		EscapeString($gold3), // '金币价格3',
		EscapeString($money3), // '比索价格3',
		EscapeString($charm), // '加魅力',
		EscapeString($goods_id)
		); 
	
	DBHelper::ExecReturnJSON($str_sql);
}

//根据等级 套装修改金币魅力等-----
function HttpAction_edit_auto_goods_dress_info()
{ 
	$level = $_REQUEST["level"]; 
	$is_checkbox_money = $_REQUEST["is_checkbox_money"];

	$type_1 = "clothing";
	$id = $_REQUEST["id"];
	$msg = "";
	
	$returnArray = array();
	
	$str_sql = sprintf("select * from t_goods_dress where id = %s",  EscapeString($id));	
	$dressArray = DBHelper::Query($str_sql, $msg);
	if($dressArray == -1)
	{
		ReturnJSONErrorMsg($msg);
		return false;
	}
	if(count($dressArray) == 0)
	{
		$retMsg = sprintf("套装ID[%s]不存在, error:%s", $id, $msg);
		ReturnJSONErrorMsg($retMsg);
		return;
	}
	
	//修改套装等级
	$str_sql = sprintf("update t_goods_dress set level = '%s' where id = '%s'", $level, $id);
	DBHelper::Exec($str_sql, $msg);
	
		//汇率
	$auto_exchange_rate_money_to_gold = GetConfInfo("auto_exchange_rate_money_to_gold"); //汇率 1比索=20金币
	
	//续费价：
	$auto_price_scale_1 = GetConfInfo("auto_price_scale_1");			//10 续费7天价为原价的10%													
	$auto_price_scale_2 = GetConfInfo("auto_price_scale_2");			//20 续费30天价为原价的20%													
	$auto_price_scale_3 = GetConfInfo("auto_price_scale_3");			//30 续费180天价为原价的50%													

	//商品时间
	$auto_goods_time = GetConfInfo("auto_goods_time");;			//有效期		30天（2592000秒）	
	$auto_goods_time_1 = GetConfInfo("auto_goods_time_1");;		//有效期1		7天（604800秒），原价10%	
	$auto_goods_time_2 = GetConfInfo("auto_goods_time_2");;  	//有效期2		30天（2592000秒），原价20%	
	$auto_goods_time_3 = GetConfInfo("auto_goods_time_3");;		//有效期3		180天（15552000秒），原价50%	
	
	//规则
	$auto_role_gold_money_array = GetConfInfo("auto_role_gold_money");
	$auto_role_charm_array = GetConfInfo("auto_role_charm"); 
	 
	$dress = $dressArray[0]["dress"];
	//WriteLog("dress:" . $dress); 
	$dress_goods_array = __get_dress_goods($dress); //从套装信息表dress字段 解析出商品信息成数组 {type_2=>goods_id} 
	foreach($dress_goods_array as $type_2 => $goods_id)  //查询套装子商品信息
	{  
			$tmpLevel = $level;  
			
			/*WriteLog("========================");
			WriteLog("goods_id:" . $goods_id);
			WriteLog("type_2:" . $type_2); 
			WriteLog("tmpLevel:" . $tmpLevel);*/
	
			  $time = $auto_goods_time;        	// '有效时间(秒)',有效期		30天（2592000秒）
			  $gold = 0;        				// '金币价格', 
			  $money = 0;        				// '比索价格',
			  
			  $time1 = $auto_goods_time_1;      // '有效时间1(秒)',有效期1		7天（604800秒），原价10%
			  $gold1 = 0;        				// '金币价格1',
			  $money1 = 0;        				// '比索价格1',
			  
			  $time2 = $auto_goods_time_2;      // '有效时间2(秒)',有效期2		30天（2592000秒），原价20%	
			  $gold2 = 0;        				// '金币价格2',
			  $money2 = 0;        				// '比索价格2',
			  
			  $time3 = $auto_goods_time_3;      // '有效时间3(秒)',有效期3		180天（15552000秒），原价50%
			  $gold3 = 0;        				// '金币价格3',
			  $money3 = 0;        				// '比索价格3',
				
			  $charm = 0;        // '加魅力',*/
				
			if(!array_key_exists($type_2, $auto_role_gold_money_array) || !array_key_exists($type_2, $auto_role_charm_array))
			{
				ReturnJSONErrorMsg("type_2[$type_2]不存在规则里...");
				return;
			} 
			
			$strRoleMoney ="return $auto_role_gold_money_array[$type_2];";  
			$money = eval($strRoleMoney);
			//WriteLog("strRoleMoney:" . $strRoleMoney);
			//WriteLog("money:" . $money);
			
			$strRoleCharm ="return $auto_role_charm_array[$type_2];";  
			$charm = eval($strRoleCharm);
			//WriteLog("strRoleCharm:" . $strRoleCharm);
			//WriteLog("charm:" . $charm);
				
			if($is_checkbox_money == "0")  //选择的是金币
			{
				$gold = $money * $auto_exchange_rate_money_to_gold;
				$money = 0;
				
				$charm = $charm - 1;
				if($charm < 0)
					$charm = 0;
			} 
			/*
			WriteLog("=====---");
			WriteLog("money:" . $money);
			WriteLog("gold:" . $gold);
			WriteLog("charm:" . $charm);*/
			
			  $gold1 = round($gold * $auto_price_scale_1 / 100);        				// '金币价格1', 原价10%
			  $money1 = round($money * $auto_price_scale_1 / 100);        				// '比索价格1', 原价10%
			  
			  $gold2 = round($gold * $auto_price_scale_2 / 100);        				// '金币价格2', 原价20%
			  $money2 = round($money * $auto_price_scale_2 / 100);        				// '比索价格2', 原价20%
			  
			  $gold3 = round($gold * $auto_price_scale_3 / 100);        				// '金币价格3',原价50%
			  $money3 = round($money * $auto_price_scale_3 / 100);        				// '比索价格3',原价50%
			
			$str_sql = sprintf("update t_goods set  
			   `level` = '%s' ,  `order_index` = '%s' ,       
			  `time` = '%s' ,   `gold` = '%s' ,   `money` = '%s' ,        
			  `time1` = '%s' ,  `gold1` = '%s' ,  `money1` = '%s' ,       
			  `time2` = '%s' ,  `gold2` = '%s' ,  `money2` = '%s' ,       
			  `time3` = '%s' ,  `gold3` = '%s' ,  `money3` = '%s' ,      
			  `charm` = '%s'     where goods_id='%s' ", 

				EscapeString($level), // '等级限制',
				EscapeString($charm), // 'order_index  魅力',
				EscapeString($time), // '有效时间(秒)',
				EscapeString($gold), // '金币价格',
				EscapeString($money), // '比索价格',
				EscapeString($time1), // '有效时间1(秒)',
				EscapeString($gold1), // '金币价格1',
				EscapeString($money1), // '比索价格1',
				EscapeString($time2), // '有效时间2(秒)',
				EscapeString($gold2), // '金币价格2',
				EscapeString($money2), // '比索价格2',
				EscapeString($time3), // '有效时间3(秒)',
				EscapeString($gold3), // '金币价格3',
				EscapeString($money3), // '比索价格3',
				EscapeString($charm), // '加魅力',
				EscapeString($goods_id)
				);  
			//WriteLog("str_sql:" . $str_sql); 
			  DBHelper::Exec($str_sql, $msg); 
	}	 
	ReturnJSONMsg("编辑成功"); 
}



//根据等级 (限量版)套装修改金币魅力等-----
function HttpAction_edit_auto_goods_dress_info_ext()
{ 
	//$level = $_REQUEST["level"]; 
	$total = $_REQUEST["total"]; 
	$is_checkbox_money = $_REQUEST["is_checkbox_money"];

	$type_1 = "clothing";
	$id = $_REQUEST["id"];
	$msg = "";
	
	$returnArray = array();
	
	$str_sql = sprintf("select * from t_goods_dress where id = %s",  EscapeString($id));	
	$dressArray = DBHelper::Query($str_sql, $msg);
	if($dressArray == -1)
	{
		ReturnJSONErrorMsg($msg);
		return false;
	}
	if(count($dressArray) == 0)
	{
		$retMsg = sprintf("套装ID[%s]不存在, error:%s", $id, $msg);
		ReturnJSONErrorMsg($retMsg);
		return;
	}
	
	//修改套装等级
	//$str_sql = sprintf("update t_goods_dress set level = '%s' where id = '%s'", $level, $id);
	//DBHelper::Exec($str_sql, $msg);
	
		//汇率
	$auto_exchange_rate_money_to_gold = GetConfInfo("auto_exchange_rate_money_to_gold"); //汇率 1比索=20金币
	
	//续费价：
	$auto_price_scale_1 = GetConfInfo("auto_price_scale_1");			//10 续费7天价为原价的10%													
	$auto_price_scale_2 = GetConfInfo("auto_price_scale_2");			//20 续费30天价为原价的20%													
	$auto_price_scale_3 = GetConfInfo("auto_price_scale_3");			//30 续费180天价为原价的50%													

	//商品时间
	$auto_goods_time = GetConfInfo("auto_goods_time");;			//有效期		30天（2592000秒）	
	$auto_goods_time_1 = GetConfInfo("auto_goods_time_1");;		//有效期1		7天（604800秒），原价10%	
	$auto_goods_time_2 = GetConfInfo("auto_goods_time_2");;  	//有效期2		30天（2592000秒），原价20%	
	$auto_goods_time_3 = GetConfInfo("auto_goods_time_3");;		//有效期3		180天（15552000秒），原价50%	
	
	//规则
	$auto_role_gold_money_array = GetConfInfo("auto_role_gold_money_limitcount");
	$auto_role_charm_array = GetConfInfo("auto_role_charm_limitcount"); 
	 
	$dress = $dressArray[0]["dress"];
	//WriteLog("dress:" . $dress); 
	$dress_goods_array = __get_dress_goods($dress); //从套装信息表dress字段 解析出商品信息成数组 {type_2=>goods_id} 
	foreach($dress_goods_array as $type_2 => $goods_id)  //查询套装子商品信息
	{  
			$tmpLevel = 0; //$level;  
			
			/*WriteLog("========================");
			WriteLog("goods_id:" . $goods_id);
			WriteLog("type_2:" . $type_2); 
			WriteLog("tmpLevel:" . $tmpLevel);*/
	
			  $time = $auto_goods_time;        	// '有效时间(秒)',有效期		30天（2592000秒）
			  $gold = 0;        				// '金币价格', 
			  $money = 0;        				// '比索价格',
			  
			  $time1 = $auto_goods_time_1;      // '有效时间1(秒)',有效期1		7天（604800秒），原价10%
			  $gold1 = 0;        				// '金币价格1',
			  $money1 = 0;        				// '比索价格1',
			  
			  $time2 = $auto_goods_time_2;      // '有效时间2(秒)',有效期2		30天（2592000秒），原价20%	
			  $gold2 = 0;        				// '金币价格2',
			  $money2 = 0;        				// '比索价格2',
			  
			  $time3 = $auto_goods_time_3;      // '有效时间3(秒)',有效期3		180天（15552000秒），原价50%
			  $gold3 = 0;        				// '金币价格3',
			  $money3 = 0;        				// '比索价格3',
				
			  $charm = 0;        // '加魅力',*/
				
			if(!array_key_exists($type_2, $auto_role_gold_money_array) || !array_key_exists($type_2, $auto_role_charm_array))
			{
				ReturnJSONErrorMsg("type_2[$type_2]不存在规则里...");
				return;
			} 
			
			if(!array_key_exists($total, $auto_role_gold_money_array[$type_2]) || !array_key_exists($total, $auto_role_charm_array[$type_2]))
			{
				ReturnJSONErrorMsg("total[$total]不存在规则里...");
				return;
			}
			
			$money = $auto_role_gold_money_array[$type_2][$total]; //从配置文件里获取
			//WriteLog("money:" . $money);
			
			$charm = $auto_role_charm_array[$type_2][$total];     //从配置文件里获取
			//WriteLog("charm:" . $charm);
				
			if($is_checkbox_money == "0")  //选择的是金币
			{
				$gold = $money * $auto_exchange_rate_money_to_gold;
				$money = 0;
				
				$charm = $charm - 1;
				if($charm < 0)
					$charm = 0;
			}  
			
			/*WriteLog("=====---");
			WriteLog("money:" . $money);
			WriteLog("gold:" . $gold);
			WriteLog("charm:" . $charm); */
			
			  $gold1 = round($gold * $auto_price_scale_1 / 100);        				// '金币价格1', 原价10%
			  $money1 = round($money * $auto_price_scale_1 / 100);        				// '比索价格1', 原价10%
			  
			  $gold2 = round($gold * $auto_price_scale_2 / 100);        				// '金币价格2', 原价20%
			  $money2 = round($money * $auto_price_scale_2 / 100);        				// '比索价格2', 原价20%
			  
			  $gold3 = round($gold * $auto_price_scale_3 / 100);        				// '金币价格3',原价50%
			  $money3 = round($money * $auto_price_scale_3 / 100);        				// '比索价格3',原价50%
			
			$str_sql = sprintf("update t_goods set  
			   `total` = '%s' ,   `order_index` = '%s' ,        
			  `time` = '%s' ,   `gold` = '%s' ,   `money` = '%s' ,        
			  `time1` = '%s' ,  `gold1` = '%s' ,  `money1` = '%s' ,       
			  `time2` = '%s' ,  `gold2` = '%s' ,  `money2` = '%s' ,       
			  `time3` = '%s' ,  `gold3` = '%s' ,  `money3` = '%s' ,      
			  `charm` = '%s'     where goods_id='%s' ", 

				EscapeString($total), // '数量限制',
				EscapeString($charm), // '排序',
				EscapeString($time), // '有效时间(秒)',
				EscapeString($gold), // '金币价格',
				EscapeString($money), // '比索价格',
				EscapeString($time1), // '有效时间1(秒)',
				EscapeString($gold1), // '金币价格1',
				EscapeString($money1), // '比索价格1',
				EscapeString($time2), // '有效时间2(秒)',
				EscapeString($gold2), // '金币价格2',
				EscapeString($money2), // '比索价格2',
				EscapeString($time3), // '有效时间3(秒)',
				EscapeString($gold3), // '金币价格3',
				EscapeString($money3), // '比索价格3',
				EscapeString($charm), // '加魅力',
				EscapeString($goods_id)
				);  
			 //WriteLog("str_sql:" . $str_sql); 
			  DBHelper::Exec($str_sql, $msg); 
	}	 
	ReturnJSONMsg("编辑成功"); 
}


?>
